package com.byteridge.purpleskills;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.util.Log;

public class HttpHelper {
	String URL;
	HttpClient httpClient;
	HttpPost request;
	StringEntity json_string;
	JSONHelper json_helper;
	HttpResponse response;

	public HttpHelper(String url) {
		URL = url;
	}

	public void HttpRequest() throws ClientProtocolException, IOException {
		httpClient = new DefaultHttpClient();
		request = new HttpPost(URL);
		json_helper = new JSONHelper();
		json_string = new StringEntity(JSONHelper.getJson());
		request.setHeader("Accept", "text/plain");
		request.setHeader("Accept-Charset", "utf-8");
		request.setHeader("Content-type", "application/json;");
		request.setEntity(json_string);
		response = httpClient.execute(request);
		Log.v("PurpleSkills", "HttpRequest response  "+response);
	}

	public String getHttpResponse() throws ParseException, IOException {
		return EntityUtils.toString(response.getEntity());
	}
}
